//
//  GRWebViewContainer.h
//  GroupCost_IOS
//
//  Created by apple on 2019/2/21.
//  Copyright © 2019年 apple. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "GRWebViewConfiguration.h"
#import "GRBaseView.h"
#import <WebKit/WebKit.h>
@interface GRScriptMessageDelegate : NSObject <WKScriptMessageHandler>

@property (nonatomic, weak) id<WKScriptMessageHandler> scriptDelegate;
- (instancetype)initWithDelegate:(id<WKScriptMessageHandler>)scriptDelegate;

@end

typedef void (^webViewTitleChangeBlock)(NSString *title);
typedef void (^webViewLoadProgressBlock)(double newValue);
typedef void (^webViewIsLoadingBlock)(void);
typedef void (^webViewLoadingShowBlock)(BOOL show);
typedef void (^startLoadBlock)(WKWebView *webView);

typedef void (^webViewStartLoadBlock)(WKWebView *webView);
typedef void (^webViewFinishLoadBlock)(WKWebView *webView);
typedef void (^webViewLoadErrorBlock)(WKWebView *webView, NSError *error);

typedef void (^webViewUrlRouteBlock)(WKNavigationAction *navigationAction ,void (^decisionHandler)(WKNavigationActionPolicy));

typedef void(^webViewReceiveAuthenticationChallengeBlock)(WKWebView *webView ,NSURLAuthenticationChallenge *challenge ,void (^completionHandler)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential));


NS_ASSUME_NONNULL_BEGIN

@interface GRWebViewContainer : GRBaseView

@property (nonatomic,strong) WKWebView *webView;

@property (nonatomic,strong) UIProgressView *progressView;

@property (nonatomic,strong) GRWebViewConfiguration *defaultConfiguration;

/**
 *  title发生变化执行的block
 */
@property (copy, nonatomic) webViewTitleChangeBlock titleDidChangeBlock;

/**
 *  加载进度的block
 */
@property (copy, nonatomic) webViewLoadProgressBlock progressChangeBlock;

/**
 *  loading加载的block
 */
@property (copy, nonatomic) webViewLoadingShowBlock loadingShowBlock;

/**
 title发生变化执行的block
 */
@property (copy, nonatomic) webViewTitleChangeBlock webViewTitleChangeBlock;

/**
 加载进度的block
 */
@property (copy, nonatomic) webViewLoadProgressBlock webViewLoadProgressBlock;

/**
 webView是否在加载
 */
@property (copy, nonatomic) webViewIsLoadingBlock webViewIsLoadingBlock;

/**
 Web内容开始在网页视图中加载时调用的block
 */
@property (copy, nonatomic) webViewStartLoadBlock webViewStartLoadBlock;

/**
 导航完成后调用的block
 */
@property (copy, nonatomic) webViewFinishLoadBlock webViewFinishLoadBlock;

/**
 当Web视图加载内容时发生错误时调用的block
 */
@property (copy, nonatomic) webViewLoadErrorBlock webViewLoadErrorBlock;

/**
 当Web视图收到服务器重定向时调用的block
 */
@property (copy, nonatomic) webViewUrlRouteBlock webViewUrlRouteBlock;

/**
 授权block
 */
@property (copy ,nonatomic) webViewReceiveAuthenticationChallengeBlock webViewAuthBlock;


- (void)loadURL:(NSURL *)URL;

- (void)loadURLstr:(NSString *)url;

- (void)loadLocalHtmlFileName:(NSString *)htmlName;


@end

NS_ASSUME_NONNULL_END
